import axios from "axios";

let baseURL = null;

// 处理环境： 开发环境 development 生产环境 production
if (process.env.NODE_ENV === "development") {
    baseURL = "/api";
} else if (process.env.NODE_ENV === "production") {
    baseURL = "";
}

// 创建自定义axios对象
const instance = axios.create({
    baseURL,
    timeout: 1000,
});

// 封装 get 请求
export function get(url, params = null) {
    return new Promise((resolve, reject) => {
        instance
            .get(url, { params })
            .then((res) => {
                resolve(res.data);
            })
            .catch((err) => {
                reject(err.data);
            });
    });
}
